<%@page language="java" contentType="text/html;charset=UTF-8" %><%@ include file="/common/taglibs.jsp"%>
<%
	String id = request.getParameter("id");
	String action = "orderOffset";
	String title = "查询";
	String url = action+"?t="+Utils.getSystemMillis();
	String stime = request.getParameter("stime");
	String etime = request.getParameter("etime"); 
	if(Utils.isNull(stime)||Utils.isNull(etime)){
		stime = Utils.getAddDate(Utils.getNowDate(),-30)+" 00:00";
		etime = Utils.getNowDate()+" 23:59";
	}
	String orderCode = request.getParameter("orderCode");
	if(Utils.isNull(orderCode)){
		orderCode = "";
	}
	String pnr = request.getParameter("pnr");
	if(Utils.isNull(pnr)){
		pnr = "";
	}
	 
	String type = request.getParameter("type");
	if(Utils.isNull(type)){
		type = Config.ORDER_TYPE_ALL+"";
	}
 
	String clientid = request.getParameter("clientid");
	if(Utils.isNull(clientid)){
		clientid = "";
	}
	String custname = request.getParameter("custname");
	if(Utils.isNull(custname)){
		custname = "";
	}else{
		custname = java.net.URLDecoder.decode(custname,"UTF-8");
	}
	String company = request.getParameter("company");
	if(Utils.isNull(company)){
		company = "";
	}else{
		company = java.net.URLDecoder.decode(company,"UTF-8");
	}
	String queryName = "&order.custname="+custname+"&order.custcompany="+company+"";
	String term = "query.stime="+stime+"&query.etime="+etime+"&orderOffset.orderCode="+orderCode+"&order.pnr="+pnr+"&order.clientid="+clientid+"&order.type="+type;
	String editJsp = jspName.replace("list","info");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title></title>    
	<link href="../ui/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
	<link href="../ui/lib/ligerUI/skins/Gray/css/dialog.css" rel="stylesheet" type="text/css" />
	<script src="../ui/lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>   
    <script src="../ui/lib/ligerUI/js/core/base.js" type="text/javascript"></script>
    <script src="../ui/lib/ligerUI/js/ligerui.all.min.js" type="text/javascript"></script> 
    <link href="../ui/lib/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
    
	<script src="../ui/helper.js" type="text/javascript"></script> 
	<script type="text/javascript">
    var grid=null; 
    var datas;
    $(function () { 
			$("#stime").ligerDateEditor({ showTime: true,initValue:'<%=stime%>'});
        	$("#etime").ligerDateEditor({ showTime: true,initValue:'<%=etime%>'}); 
        	
	  		$("form").ligerForm();
	  		var url1 = '<%=url%>&<%=term%>'+encodeURI(encodeURI('<%=queryName%>'));
	  		$.getJSON(url1,
	  	            function(json) 
	  	            {
                datas=json;
	  		myGrid= $("#grids").ligerGrid({
        		 checkbox: true,
                 columns:[	{ display: '编号', name: 'offsetId', width: 100},
                             { display: '客户编码', name: 'customerId' },
                             { display: '转账单号', name: 'transferId', width: 120 },
                             { display: '转账单金额', name: 'offsetTransferAmounts', width: 150,type:'float' },
                             { display: '关联财务单号', name: 'financialOrderCodes', width: 120 },
                             { display: '关联财务单总额', name: 'offsetFinancialAmountsAll', width: 150,type:'float' },
                             { display: '冲账金额', name: 'offsetAmounts', width: 150,type:'float' },
                             { display: '余额', name: 'balance', width: 150,type:'float' },
                             { display: '状态', name: 'offsetState',width: 100,render: function (rowdata, rowindex){
	                            	if(rowdata.offsetState=='0'){
	                            		return '生效';
	                            	}else if(rowdata.offsetState=='1'){
	                            		return '失效';
	                            	}
	                             }},
                             { display: '创建人', name: 'creater' },
                             { display: '创建时间', name: 'createTime' }
                             ], 
                             usePager : true,
                             isScroll: true, showToggleColBtn: false, width: '100%',
                             height:'95%',
                             data:datas,
                             usePager : false,
                             url: url1,
                 			 showTitle: false, columnWidth: 100  , frozen:false,
                 			toolbar: { items: [{ text: '开始时间：<%=stime%>'},{ line:true },
					                           { text: '结束时间：<%=etime%>'},{ line:true },
					                           { text: '自定义查询',click:f_inputQuery, icon: 'search2'},{ line:true },
					                           //{ text: '添加',click:f_addOrderOffset, icon: 'plus'},{ line:true },
					                           { text: '作废',click:f_delOrderOffset, icon: 'delete',id : 'del'},{ line:true },
                                               { text: '导出Excel', id : 'orderSumbit' ,click: downloadThis, icon: 'add' ,icon: 'save' }
                                               ]
                                               },totalRender: f_totalRender,isChecked: f_isChecked, onCheckRow: f_onCheckRow, onCheckAllRow: f_onCheckAllRow
         
             });
    	});
    });    
	function f_totalRender(){
		return datas.totalRender;
	}
	
	function submitThis(){
		form1.action = "<%=jspName%>"; 
		form1.submit();
	}
	
 	function downloadThis(){
		form1.action = "../common/download.jsp?name=<%=jspName%>"; 
		form1.fb.value = getDatasValue(datas);	
		form1.submit();
	}
 	
 	function f_onSelectRow(data, rowindex, rowobj){
 		form1.action = "<%=action%>?action=view&orderOffset.orderOffsetCode="+data.HideID;
		form1.submit();
 	}
 	
 	function f_inputQuery(){
		$.ligerDialog.open({ target: $("#target1"),title:'<%=title%>',height: 300,width: 500,isResize: true,showMax:true, 
			buttons: [
			{ text: '清空', 
			onclick: function (item, dialog) {
				//$("#stime").val("");
				//$("#etime").val("");
				$("#orderCode").val("");
				$("#pnr").val("");
				$("#clientid").val("");
 				$("#type").ligerGetComboBoxManager().setValue(<%=Config.ORDER_TYPE_ALL%>);
			} },
			{ text: '确定', 
				onclick: function (item, dialog) {
					var url = '<%=jspName%>?stime='+ $("#stime").val()
					 	+'&etime='+$("#etime").val()+'&custname='+encodeURI(encodeURI($("#clientName").val()))+'&company='+encodeURI(encodeURI($("#company").val()))+'';
					 
					 location.href = url;
				} },
			{ text: '取消', onclick: function (item, dialog) { dialog.hide(); } } ] });
    }
	
	 function f_onCheckAllRow(checked)
        {	 
            for (var rowid in this.records)
            {
                if(checked)
                    addCheckedOrderOffset(this.records[rowid]);
                else
                    removeCheckedOrderOffset(this.records[rowid]);
            }
        }
 
        var checkedOrderOffset = [];
        function findCheckedOrderOffset(obj)
        {
            for(var i =0;i<checkedOrderOffset.length;i++)
            {
                if(checkedOrderOffset[i] == obj) return i;
            }
            return -1;
        }
        function addCheckedOrderOffset(obj)
        {
            if(findCheckedOrderOffset(obj) == -1)
                checkedOrderOffset.push(obj);
        }
        function removeCheckedOrderOffset(obj)
        {
            var i = findCheckedOrderOffset(obj);
            if(i==-1) return;
            checkedOrderOffset.splice(i,1);
        }
        function f_isChecked(rowdata)
        {
            if (findCheckedOrderOffset(rowdata) == -1)
                return false;
            return true;
        }
        function f_onCheckRow(checked, data)
        {
            if (checked) addCheckedOrderOffset(data);
            else removeCheckedOrderOffset(data);
        }
        function f_getChecked()
        {
            alert(checkedOrderOffset.join(','));
        }
        function f_addOrderOffset(){
				location.href = "<%=editJsp%>?action=add" ;  
	    }
		function f_editOrderOffset(){
			if(checkedOrderOffset.length==0){
				 $.ligerDialog.warn('<br/>请选择一条记录');
				 return ;	
			}else if(checkedOrderOffset.length>1){
				$.ligerDialog.warn('<br/>您选择了'+checkedOrderOffset.length+'笔费用<br/><br/>请选择单条记录');
				return;
			}
			form1.action = "<%=action%>?action=display&orderOffset.orderOffsetCode="+checkedOrderOffset[0].HideID;
			form1.submit();   
        }

       	function f_inputOrderOffset(){
       		 $.ligerDialog.prompt('请输入用户ID,不输入则查询全部','', function (yes, value)
             {
                      	if (yes){
                         	f_findUser(value);
                        }
             });
       	}
        
        function f_delOrderOffset()
        {
        	if(checkedOrderOffset.length==0){
				 $.ligerDialog.warn('<br/>请选择一条记录');
				 return ;	
			}
        	var codes = "";
        	for(var i=0;i<checkedOrderOffset.length;i++){
        		if(i==0){
        			codes += ""+checkedOrderOffset[i].HideID;
        		}else{
        			codes += ","+checkedOrderOffset[i].HideID;
        		}
        	}
        	
			//$.ligerDialog.confirm('<br/>确定要删除选中的记录吗？',
                 	//function (yes) {
	                 	//if(yes==true) {
	                 		form1.action = "<%=action%>?action=delete&orderOffset.orderOffsetCodes="+codes;
							form1.submit();   
	                 	//}
                 	//} 
            //);
            //alert(checkedCustomer.join(','));
        }
</script>
	 
</head>
<body style="padding:0 2px 2px 2px;overflow:hidden;" >
<form name="form1" method="post" id="form1">
<textarea name="fb"  style="display:none" ></textarea>
</form> 
<div >
<div id='grids' ></div></div>
<div id="target1"  style="display:none" >
  <table height="72" cellpadding="0" cellspacing="0" class="l-table-edit" >
    <tr>
  	  	<td width="59"   align="right" class="l-table-edit-td">开始时间:</td>
    	<td width="128"   align="left" class="l-table-edit-td"><input type="text" id="stime" name="stime" /></td>
    	<td colspan="2" align="right" class="l-table-edit-td">结束时间:</td>
  	  	<td width="201"  colspan="2" align="left" class="l-table-edit-td"><input type="text" id="etime" name="etime" /></td>
	</tr>
    <%--<tr>
      <td align="right" class="l-table-edit-td">订单号:</td>
      <td align="left" class="l-table-edit-td"><input type="text" id="orderCode" name="orderCode" value="" /></td>
      <td colspan="2" align="right" class="l-table-edit-td">订单类型:</td>
      <td colspan="2" align="left" class="l-table-edit-td"><input name="type" type="text" id="type" ltype="text"  value="" /></td>
    </tr> 
    <tr>
      <td align="right" class="l-table-edit-td">转账单号:</td>
      <td align="left" class="l-table-edit-td"><input type="text" id="orderCode" name="orderCode" value="" /></td>
      <td align="right" class="l-table-edit-td">财务单号:</td>
      <td align="left" class="l-table-edit-td"><input type="text" id="orderCode1" name="orderCode1" value="" /></td>
    </tr> 
    --%>
    <tr>
      <td align="right" class="l-table-edit-td">PNR:</td>
      <td align="left" class="l-table-edit-td"><input type="text" id="pnr" name="pnr" value="" /></td>
      <td colspan="2" align="right" class="l-table-edit-td">公司名称:</td>
      <td colspan="2" align="left" class="l-table-edit-td"><input type="text" id="company" name="company" value="" /></td>
    </tr>
    <tr>
      <td align="right" class="l-table-edit-td">客户名称:</td>
      <td align="left" class="l-table-edit-td"><input type="text" id="clientName" name="clientName" value="" /></td>
      <td colspan="2" align="right" class="l-table-edit-td">PNR:</td>
      <td colspan="2" align="left" class="l-table-edit-td"><input type="text" id="pnr" name="pnr" value="" /></td>
    </tr>
    <tr>
      <td align="right" class="l-table-edit-td">客户ID:</td>
      <td align="left" class="l-table-edit-td"><input type="text" id="clientid" name="clientid" value="" /></td>
      <td colspan="2" align="right" class="l-table-edit-td">创建人工号:</td>
      <td colspan="2" align="left" class="l-table-edit-td"><input type="text" id="workno" name="workno" value="" /></td>
    </tr>
</table> 
 </div>
</body>
</html>
